package cn.wolfcode.trip.base.service.impl;

import cn.wolfcode.trip.base.domain.Region;
import cn.wolfcode.trip.base.mapper.RegionMapper;
import cn.wolfcode.trip.base.query.QueryObject;
import cn.wolfcode.trip.base.query.RegionQueryObject;
import cn.wolfcode.trip.base.service.IRegionService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

@Service
public class RegionImpl implements IRegionService {
    @Autowired
    private RegionMapper regionMapper;

    @Override
    public List<Region> query(QueryObject qo) {

        return regionMapper.selectForList(qo);
    }

    @Override
    public List<Region> getRegionsByParentId(Long parentId) {
       return regionMapper.selectRegionsByParentId(parentId);
    }

    @Override
    public void saveOrUpdate(Region region) {
        if (region.getId() != null) {
            //更新
            regionMapper.updateByPrimaryKey(region);
        }else {
            //保存
            regionMapper.insert(region);
        }
    }

    @Override
    public List<Region> list() {
        return regionMapper.selectAll();
    }

    @Override
    public List<Region> getCommendRegions(RegionQueryObject qo) {
        return regionMapper.selectForList(qo);
    }
}
